package ArrayList;

import java.util.ArrayList;

public class Phone_test2 {
    public static void main(String[] args) {
        ArrayList<Phone> list=new ArrayList<>();
        Phone p1=new Phone(2000,"mi");
        Phone p2=new Phone(3000,"iphone");
        Phone p3=new Phone(4000,"huawei");
        list.add(p1);
        list.add(p2);
        list.add(p3);
        ArrayList<Phone> newlist=getArrlist(list);
        for (int i = 0; i < newlist.size(); i++) {
            System.out.println(newlist.get(i).getName()+" "+newlist.get(i).getPrice());
        }
    }
    public static ArrayList<Phone> getArrlist(ArrayList<Phone> list){
        // 定义一个新的集合 用于存放价格低于三千的手机信息
        ArrayList<Phone> newList=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getPrice()<3000){
                newList.add(list.get(i));
            }
        }
        return newList;
    }
}
